<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">

        <hello-world :str='str'@send-event='getFn'></hello-world>
        <div>===========================================</div>
    </div>

    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
        Vue.component('hello-world',{
            data() {
                return {
                    msg:'hello'
                }
            },
            methods: {
                sendtFn(){
                    this.$emit('send-event',this.msg)
                }
            },
            props:['str'],
            template:`
                <div>
                    <h3> 我是子组件私有数据：{{msg}}</h3>
                    <h3>父组件传给子组件的数据: {{str}}</h3>
                    <button @click='sendtFn'>子组件向父组件传数据</button>
                </div>
            `,
        })
        new Vue({
            el:'#app',
            data() {
                return {
                    str:'我是父组件的数据'
                }
            },
            methods: {
                getFn(p){
                    console.log('这是子组件传给父组件的值',p);
                }
            },
        })
    </script>
</body>
</html>